// console.log("我是index.html的互动脚本");

let backtopTimer=null;

const totop=document.querySelector("#totop");
totop.style.display="none";


const baseUrl="http://localhost:9999";

const apis={
    renderHead:{
        path:"/head",
        callback: renderHead,
    },
}

function renderHead(res){
     let html =""
     const {data}=res;
     console.log({data})
    //  console.log({data}[0]);
     console.log({data}.data.resultList[0].title);
     for(let i=1;i<9;i++){
        //  const item = i === 0 ? data[i][0]:data[i];
         const item =i ===0?{data}.data.resultList[i][0]:{data}.data.resultList[i];
        //  console.log(item);
        //  console.log(item.title)
         html+=`<li class="item cate"><a href="http://www.qdaily.com/tags/1068.html">${item.title}</a></li>` 
        //  html+=	123
     }
    //  document.querySelector(".items cates").innerHTML=html;
     let cok=document.querySelector("#items1");
     cok.innerHTML=html;

}
window.addEventListener(
    "scroll",
    scrollHandler
) 
function scrollHandler(e){
    if(document.documentElement.scrollTop<700){
        totop.style.display="none";
    }
    else{
        totop.style.display="block";
    }
}


document.querySelector(".totop-bd").onclick=function(e){
    if(!backtopTimer){
        backtopTimer=setInterval(()=>{
            if(document.documentElement.scrollTop>100){
                document.documentElement.scrollTop -=300;
            }else{
                document.documentElement.scrollTop =0;
                if(backtopTimer){
                    clearInterval(backtopTimer);
                    backtopTimer=null;
                } 
            }
        },50);
    }
};




ajaxPromise({
    url:`${baseUrl}${apis.renderHead.path}`,
})
.then((data)=>{
    console.log("data got",data)
    apis.renderHead.callback(data);
})
    
.catch((err)=>console.error("err got",err));

import Swiper  from "../js/swiper-bundle.esm.browser.js";
var swiper = new Swiper(".mySwiper", {
    slidesPerView: 1,
    spaceBetween: 0,
    loop: true,
    pagination: {
      el: ".swiper-pagination",
      clickable: true,
    },
    autoplay:
    {
        delay:1000
    },
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
});
